package com.yyfax.ph.home.recommendloan.basicinfo;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

public class CheckInBasicInfoModel extends Model {

	private static final String TAG = "CheckInBasicInfoModel";

	protected static final int MSG_CHECK_BASIC_INFO = 19;
	protected static final int MSG_CHECK_ADMITTANCE = 20;

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		BaseResultEntity result = cast(obj);
		switch (result.requestCode) {
			case MSG_CHECK_BASIC_INFO:
				BasicInfoResult rsa = cast(obj);
				EventAgent.post(rsa);
				break;
			case MSG_CHECK_ADMITTANCE:
				AdmittanceResult notify = cast(obj);
				EventAgent.post(notify);
				break;
		}
	}

	@Override
	public Observable getObservable(Object obj, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		switch (functionalCode) {
			case MSG_CHECK_BASIC_INFO:
				return service.checkBasicInfo(token, (BasicInfo) obj);
			case MSG_CHECK_ADMITTANCE:
				return service.getAdmittance(token, (Admittance) obj);
		}
		return null;
	}

	private interface Service {
		@POST("apply/permission/getAdmittance")
		Observable<AdmittanceResult> getAdmittance(@Header("token") String token, @Body Admittance admittance);

		@POST("apply/record/basic")
		Observable<BasicInfoResult> checkBasicInfo(@Header("token") String token, @Body BasicInfo basicInfo);
	}

	protected static class Admittance {
		String certId;// 身份证号，加密                              |
		String name;//用户名                                      |
		String type;//推荐类型，简易推荐：simpleRefer，其它可不传
	}

	public static class SingleContentBean {
		public String code;
	}

	static class AdmittanceResult extends BaseResultEntity<SingleContentBean> {

	}

	protected static class BasicInfo {
		public String rcmdId; // 推荐编号
		public String outletId; // 常住城市
		public String certId; // 身份证（RSA加密）
		public String name; // 姓名
		public String phone; // 手机号（RSA加密）
		public String customerMgr; // 客户经理编号
		public String type; // 是否有纸质征信报告（0：否 1:是）
		public String ethnicity; // 民族
		public String address; // 地址
		public String authority; // 签发机关
		public String validity; // 有效期（格式：yyyyMMdd-yyyyMMdd 或 yyyyMMdd-长期）
		public String certPhoto; // 证件照id
		public String sex; // 性别
	}

	public static class CheckBasicInfoBean {
		public String rcmdId = "";
		public String code = "";
	}

	static class BasicInfoResult extends BaseResultEntity<CheckBasicInfoBean> {

	}
}
